package com.qin.mall.controller.discountController;

import com.qin.mall.openfeign.discount.SmsFlashPromotionProductRelationFeigin;
import com.qin.mall.common.api.CommonResult;
import com.qin.mall.common.api.MyBatisPlusPage;
import com.qin.malldiscount.domain.SmsFlashPromotionProductRelation;
import com.qin.malldiscount.dto.SmsFlashPromotionProduct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Leisure
 * create 2022 2022/11/25 2:27
 **/
@RestController
@RequestMapping("/flashProductRelation")
public class FlashPromotionProductRelationController {
    
    @Autowired
    private SmsFlashPromotionProductRelationFeigin flashPromotionProductRelationFeigin;

    /**
     * 批量选择商品添加关联
     */
    @PostMapping("/create")
    @ResponseBody
    public CommonResult create(@RequestBody List<SmsFlashPromotionProductRelation> relationList){
        CommonResult result = flashPromotionProductRelationFeigin.create(relationList);
        return result;
    }

    /**
     * 修改关联相关信息
     */
    @PostMapping("/delete/{id}")
    @ResponseBody
    public CommonResult delete(@PathVariable Long id){
        CommonResult count = flashPromotionProductRelationFeigin.delete(id);
        return count;
    }

    /**
     * 获取管理商品促销信息
     */
    @GetMapping("/{id}")
    @ResponseBody
    public CommonResult<SmsFlashPromotionProductRelation> getItem(@PathVariable Long id){
        CommonResult<SmsFlashPromotionProductRelation> item = flashPromotionProductRelationFeigin.getItem(id);
        return item;
    }

    /**
     * 分页查询不同场次关联及商品信息
     */
    @GetMapping("/list")
    @ResponseBody
    public CommonResult<MyBatisPlusPage<SmsFlashPromotionProduct>> list(@RequestParam(value = "flashPromotionId") Long flashPromotionId,
                                                                        @RequestParam(value = "flashPromotionSessionId") Long flashPromotionSessionId,
                                                                        @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
                                                                        @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum){
        List<SmsFlashPromotionProduct> list = flashPromotionProductRelationFeigin.list(flashPromotionId, flashPromotionSessionId, pageSize, pageNum);
        MyBatisPlusPage<SmsFlashPromotionProduct> pages = MyBatisPlusPage.getPages(pageNum.longValue(), pageSize.longValue(), list);
        return CommonResult.success(pages);
    }


    /**
     * 修改关联相关信息
     */
    @PostMapping("/update/{id}")
    @ResponseBody
    public CommonResult update(@PathVariable Long id, @RequestBody SmsFlashPromotionProductRelation relation){
        CommonResult count = flashPromotionProductRelationFeigin.update(id, relation);
        return count;
    }
}
